package com.mjf.io.input;

import org.junit.Test;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

/**
 * 处理流（包装流）：对节点流进行了封装
 */
public class BufferedReaderUse {

    @Test
    public void read() {
        String filePath = "D:\\coding\\idea\\java-stu\\src\\main\\java\\com\\mjf\\io_input\\FileReaderUse.java";
        String line;

        BufferedReader br = null;

        try {
            br = new BufferedReader(new FileReader(filePath));
            while((line = br.readLine()) != null) { // 按行读取文件，文件读取结束之后返回null
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(br != null) {
                    br.close(); // 关闭处理流底层会关闭节点流
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

}
